namespace CSharpPro._0930;

public class Demo
{
    public void TestPrint1()
    {
        Console.WriteLine("请输入三个整数：");
        int x = int.Parse(Console.ReadLine());
        int y = int.Parse(Console.ReadLine());
        int z = int.Parse(Console.ReadLine());

        int temp;
        if (x > y)
        {
            temp = x;
            x = y;
            y = temp;
        }
        if (x > z)
        {
            temp = x;
            x = z;
            z = temp;
        }
        if (y > z)
        {
            temp = y;
            y = z;
            z = temp;
        }

        Console.WriteLine($"从小到大排序为：{x}, {y}, {z}");
    }

    public void TestPrint2()
    {
        int sum = 0;
        for (int i = 1; i <= 100; i++)
        {
            if (i % 7 != 0 && !i.ToString().Contains("7"))
            {
                Console.WriteLine(i+"");
                sum += i;
            }
        }
        Console.WriteLine($"\n这些数的和为：{sum}");
    }

    public void TestPrint3()
    {
        for (int i = 1; i <= 9; i++)
        {
            for (int j = 1; j <= i; j++)
            {
                Console.WriteLine($"{j}x{i} = {i*j}\t");
            }
            Console.WriteLine();
        }
    }

    public void TestPrint4()
    {
        for (int i = 1; i < 1000; i++)
        {
            int sum = 0;
            for (int j = 1; j < i; j++)
            {
                if (i % j == 0)
                {
                    sum += j;
                }
            }
            if (sum == i)
            {
                Console.WriteLine(i);
            }
        }
    }

    public void TestPrint5()
    {
        Console.WriteLine("请输入一个正整数：");
        string numStr = Console.ReadLine();
        int digitCount = numStr.Length;
        Console.WriteLine($"它是{digitCount}位数");

        Console.Write("逆序各位数字为：");
        for (int i = digitCount - 1; i >= 0; i--)
        {
            Console.Write(numStr[i]);
        }
        Console.WriteLine();
    }

    public void TestPrint6()
    {
        Console.WriteLine("请输入菱形的行数（奇数）：");
        int n = int.Parse(Console.ReadLine());
        int mid = n / 2 + 1;

        for (int i = 1; i <= n; i++)
        {
            int spaceCount;
            int starCount;
            if (i <= mid)
            {
                spaceCount = mid - i;
                starCount = 2 * i - 1;
            }
            else
            {
                spaceCount = i - mid;
                starCount = 2 * (n - i + 1) - 1;
            }

            for (int j = 0; j < spaceCount; j++)
            {
                Console.Write(" ");
            }
            for (int j = 0; j < starCount; j++)
            {
                Console.Write("*");
            }
            Console.WriteLine();
        }
    }
}